package org.lql.algo.codecrush.week008;

/**
 * @author: liangqinglong
 * @date: 2025-08-19 00:01
 * @description: 面试题 01.02. 判定是否互为字符重排 <a href="https://leetcode.cn/problems/check-permutation-lcci/description/">...</a>
 **/
public class CheckPermutation {

	public boolean CheckPermutation(String s1, String s2) {
		if (s1.length() != s2.length()) {
			return false;
		}
		int[] count = new int[26];
		for (int i = 0; i < s1.length(); i++) {
			count[s1.charAt(i) - 'a']++;
			count[s2.charAt(i) - 'a']--;
		}
		for (int j : count) {
			if (j != 0) {
				return false;
			}
		}
		return true;
	}

	public static void main(String[] args) {
		CheckPermutation checkPermutation = new CheckPermutation();
		System.out.println(checkPermutation.CheckPermutation("abc", "bca"));
		System.out.println(checkPermutation.CheckPermutation("abc", "bad"));
	}
}
